package com.example.design.filter.filter;


import com.example.design.DateUtils;
import com.example.design.filter.ScheduleFilter;
import com.example.design.filter.context.ScheduleContext;
import com.example.design.filter.context.ScheduleUser;
import com.example.design.filter.enums.ScheduleTagEnum;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 周*不上班
 */
public class NoWorkFilter implements ScheduleFilter {

    public static final ScheduleFilter instance = new NoWorkFilter();

    @Override
    public void filter(ScheduleContext context) {
        ScheduleTagEnum noWorkTag = ScheduleTagEnum.getByDayOfWeek(
                context.getScheduleDate().getDayOfWeek().getValue()
        );
        Date date = DateUtils.localDate2Date(context.getScheduleDate());

        List<ScheduleUser> noWorkUsers = context.getScheduleUsers().parallelStream()
                .filter(user -> user.getTags() != null && user.noWorkToday(noWorkTag, date))
                .collect(Collectors.toList());
        context.addRestUsers(noWorkUsers);
    }

}
